package com.situ.mallsdauweb.hander;

import com.situ.mallsdauweb.exception.NotLoginException;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.xml.ws.Response;
import java.util.HashMap;
import java.util.Map;

//全局异常处理器
//一出异常就进这
@ControllerAdvice
public class GlobalExceptionHander {
    //如果出现没登陆异常
    @ExceptionHandler(NotLoginException.class)
    public ResponseEntity handle3(Exception e){
        Map<String,String> map = new HashMap<>();
        map.put("msg","没登录,请先登录");
        return ResponseEntity.status(401).body(map);
    }

    @ExceptionHandler(NullPointerException.class)
    public ResponseEntity handle2(Exception e){
        e.printStackTrace();
        return null;
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity handle1(Exception e){
        e.printStackTrace();
        return null;
    }
}
